package com.tutor.lzm.function.parents.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.tutor.lzm.R;
import com.tutor.lzm.adapter.MyTeacherAdapter;
import com.tutor.lzm.bean.DeliveryTeacherBean;
import com.tutor.lzm.bean.TeacherDetailInfo;
import com.tutor.lzm.view.RoundImageView;
import com.tutor.syslib.Logs;
import com.tutor.syslib.util.TextUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zzgpc on 2017-10-15.
 */
public class DeliveryTeacherAdapter extends BaseAdapter {
    private Context mCtx;
    private List<DeliveryTeacherBean> mShowList;


    public DeliveryTeacherAdapter(Context context, List<DeliveryTeacherBean> list) {
        this.mCtx = context;
        this.mShowList = list;

    }

    @Override
    public int getCount() {
        return mShowList.size();
    }

    @Override
    public Object getItem(int position) {
        return mShowList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Logs.d("TeacherAdapter", "当前位置 position = " + position);
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mCtx).inflate(R.layout.item_my_teacher, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        DeliveryTeacherBean bean = mShowList.get(position);
        Picasso.with(mCtx)
                .load(bean.headImage)
                .error(R.mipmap.personal_default)
                .into(viewHolder.imgTeacher);
        if (!TextUtil.isNull(bean.name)) {
            viewHolder.tvTitle.setText(bean.name + "老师");
        }
        viewHolder.tvMessage.setText(bean.isStuText + ",  " + bean.categoryTypeText + bean.categoryTypeText + ",  教龄" + bean.workingAge + "年");
        return convertView;
    }


    class ViewHolder {
        @BindView(R.id.img_teacher)
        RoundImageView imgTeacher;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_message)
        TextView tvMessage;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}